package com.yss.sofa.report.engine.cell.invisible;

import java.util.regex.Pattern;

import com.yss.sofa.report.engine.cell.ReportCell;

public class InvisibleCell extends ReportCell {
	private static final long serialVersionUID = 608244245112932712L;
	protected static final Pattern PATTERN=Pattern.compile("^[a-zA-Z][a-zA-Z0-9_]*$");
	protected String code;
	protected void init() {
		super.init();
	}
	public void assignTo(ReportCell cell){
		InvisibleCell _=(InvisibleCell)cell;
		super.assignTo(_);
		_.code=this.code;
	}
	public InvisibleCell create(){
		InvisibleCell _=new InvisibleCell();
		this.assignTo(_);
		return _;
	}
	public String getCode() {
		return code;
	}

	public void setCode(String code) throws Exception {
		if(!PATTERN.matcher(code).find()){
			throw new Exception("code["+code+"]必须为合法标识符");
		}
		this.code = code;
	}
	
	public int hashCode(){
		return code.hashCode();
	}
	public boolean equals(Object obj){
		if(obj instanceof InvisibleCell){
			return this.code.equalsIgnoreCase(((InvisibleCell)obj).code);
		} else {
			return false;
		}
	}
}
